<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="申请人">
          <el-input v-model="queryParam.qry_user" placeholder="工号或姓名"></el-input>
        </el-form-item>
        <el-form-item label="项目编号">
          <el-input v-model="queryParam.qry_projectnumber" placeholder=""></el-input>
        </el-form-item>
        <el-form-item label="单据日期" prop="qry_begindocdate">
          <el-date-picker v-model="queryParam.qry_begindocdate" type="date" style="width:150px" value-format="yyyy-MM-dd" placeholder="开始时间" />至
          <el-date-picker v-model="queryParam.qry_enddocdate" type="date" style="width:150px" value-format="yyyy-MM-dd" placeholder="结束时间" />
        </el-form-item>
        <el-form-item label="单据状态">
          <el-select v-model="queryParam.qry_state" clearable>
            <el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="item.code" clearable />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0" :isDisplayAdd="false">
      <template slot="left-btn">
        <el-button type="primary" icon="el-icon-plus" @click="openAddProcessProject('editForm')">新增流程建设项目</el-button>
      </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column>
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="projectnumber" label="项目编号" width="200px" sortable="custom" sort-by="projectnumber" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectname" label="项目名称" min-width="200px" sortable="custom" sort-by="projectname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispapprovalprojecttype" label="审批项目类型" min-width="150px" sortable="custom" sort-by="projectname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="applydeptname" label="所属部门" width="280px" sortable="custom" sort-by="applydeptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectlevel" label="项目级别" width="100px" sortable="custom" sort-by="projectlevel" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmanager" label="项目经理" width="80px" sortable="custom" sort-by="projectmanager" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="bidcycle" label="项目周期(天)" width="110px" sortable="custom" sort-by="bidcycle" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planstartdate" label="计划开始日期" width="120px" sortable="custom" sort-by="planstartdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planenddate" label="计划结束日期" width="120px" sortable="custom" sort-by="planenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="sponsor" label="Sponsor" width="120px" sortable="custom" sort-by="sponsor" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="owner" label="Owner" width="120px" sortable="custom" sort-by="owner" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="100px" v-slot="scope">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item type="text" icon="el-icon-edit" :disabled="scope.row.state !== 0 && scope.row.state !== 2" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
              <el-dropdown-item type="text" icon="el-icon-delete" :disabled="scope.row.state !== 0 && scope.row.state !== 2" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { checkPermission } from '@tapui/utils/permission'
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'gpmProject',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: 'SD项目立项-列表查询',
      urlPrefix: '/sd/project/',
      url: {
        queryCodeList: '/sd/project/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'modifiedon',
        sord: 'desc'
      },
      filtersInfo: {
        qry_projectmenu: "1",
        qry_whetherhistorydata: "0"
      }
    }
  },
  methods: {
    /** 打开新增对话框之前 */
    beforeOpenAddDialog(editForm, rowData) {
      this.$refs[editForm].isProcessProject = '0'
      return true
    },
    /** 打开新增对话框实现 */
    openAddProcessProject(editForm, rowData) {
      if (!this.beforeOpenAddDialog(editForm, rowData)) {
        return
      }
      this.$refs[editForm].isProcessProject = '1'
      this.$refs[editForm].isAdd = true
      this.$refs[editForm].visible = true
      this.$refs[editForm].disableEditSubmit = false
      this.$nextTick(() => {
        this.afterOpenAddDialog(editForm, rowData)
      })
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    doRowDbClick(row, column, event) {
      if (row.state === 1 || row.state === 9 || row.usercode !== this.user.code) {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      } else {
        this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    /** 改变审核状态标签颜色 */
    changeStateType(state) {
      return state === 0 ? 'info' : state === 2 ? 'danger' : state === 9 ? 'success' : ''
    }
  }
}
</script>

<style scoped></style>

